package com.yxh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yxh.dao.MakingsMapper;
import com.yxh.pojo.Makings;
import com.yxh.service.FlowManageService;
import com.yxh.service.MakingsService;
import com.yxh.util.SnowflakeIdWorker;
import com.yxh.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2018/7/4.
 */



@Service
@Transactional
public class MakingsServiceImpl implements MakingsService {


    @Autowired
    private MakingsMapper makingsMapper;
    @Autowired
    private FlowManageService flowManageService;


    @Override
    public int save(Makings hide) {
        try {
            String imgs=hide.getImgId();
            if(StringUtil.isNotEmpty(imgs)){
                String id= SnowflakeIdWorker.creatId();
                flowManageService.insertImgs(imgs,id);
                hide.setImgId(id);
            }
            return makingsMapper.insertSelective(hide);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public Map<String, Object> getById(String makingsId) {
        Map<String, Object> m=makingsMapper.selectByPrimaryKey(makingsId);
        if(m!=null&&m.get("auditingId")!=null)
            m.put("auditingName", flowManageService.nameBack(m.get("auditingId").toString()));

        return m;
    }

    @Override
    public void updata(Makings hide) {

        makingsMapper.updateByPrimaryKeySelective(hide);
    }

    @Override
    public Map<String, Object> getNewById(String id) {
        return null;
    }

    @Override
    public PageInfo getInformation(Makings hide, Integer limit, Integer offset) {
        PageHelper.startPage(limit, offset);
        List<Map<String,Object>> menuList =makingsMapper.selectByMakings(hide);
        PageInfo pageInfo = new PageInfo(menuList);
        pageInfo.setList(menuList);
        return pageInfo;
    }
}
